package com.hrt.manage.product.dao.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

import com.hrt.base.BaseDaoImpl;
import com.hrt.bean.GiftDetail;
import com.hrt.bean.GiftGroup;
import com.hrt.manage.product.dao.GiftGroupDao;

@Repository
public class GiftGroupDaoImpl extends BaseDaoImpl<GiftGroup> implements GiftGroupDao{
	
	@SuppressWarnings({ "rawtypes", "unchecked" })
	@Override
	public List<GiftGroup> queryPageByCondition(List conditions, int pageIndex,
			int pageSize) {
		String hql = "select giftGroup from GiftGroup giftGroup";
		Map delcon = new HashMap();
		delcon.put("field", "isdelete");
		delcon.put("value", 0);
		conditions.add(delcon);
		for (int i = 0; i < conditions.size(); i++) {
			Map con = (Map) conditions.get(i);
			String field = con.get("field").toString();
			String val = con.get("value").toString();
			if (i == 0) {
				hql = hql + " where giftGroup." + field + "=" + val;
			} else {
				hql = hql + " and giftGroup." + field + "=" + val;
			}
		}
		List<GiftGroup> results = queryByPage(hql, pageIndex, pageSize);
		return results;
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<GiftGroup> findIspush(GiftDetail giftDetail) {
		return this.getHibernateTemplate().find("from GiftGroup gigr where gigr.isdelete=0 and gigr.giftDetail.id="+giftDetail.getId());
	}

	/**根据礼品规格的ID找到产品组合的列表*/
	@SuppressWarnings("unchecked")
	@Override
	public List<GiftGroup> queryGiftGroupByGdId(Long gdId) {
		return this.getHibernateTemplate().find("FROM GiftGroup gigr WHERE gigr.isdelete=0 and gigr.gdeId = '"+gdId+"'");
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<GiftGroup> getGroupIdforId(Long id) {
		return this.getHibernateTemplate().find("FROM GiftGroup gigr WHERE gigr.isdelete=0 and gigr.giftDetail.id="+id);
	}


}
